package com.aimee.threadtestdemo;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_open_thread, R.id.btn_close_thread})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_open_thread:
                startTestThread();
                break;
            case R.id.btn_close_thread:
                break;
        }
    }

    private void startTestThread() {
        for (int i=0; i<300; i++) {
            TestThread testThread = new TestThread();
            testThread.start();
        }
    }

    private static class TestThread extends Thread {

        private boolean isStop =false;

        @Override
        public void run() {
            while (!isStop) {
                try {
                    Thread.sleep(10 * 1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        public void exit() {
            isStop = true;
        }
    }
}
